<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSpotOrdersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('trading_spot_orders', function (Blueprint $table) {
            $table->increments('id')->comment('订单ID');
            $table->string('symbol')->comment('交易对符号');
            $table->unsignedInteger('user_id')->comment('用户ID');
            $table->unsignedInteger('coin_id')->comment('币种ID');
            $table->unsignedInteger('market_id')->comment('交易区ID');
            $table->enum('side', ['BUY', 'SELL'])->comment('方向');
            $table->enum('type', ['LIMIT', 'MARKET'])->comment('类型');
            $table->unsignedDecimal('price', 20, 8)->nullable()->default(0)->comment('价格');
            $table->unsignedDecimal('number', 20, 8)->comment('数量');
            $table->unsignedDecimal('fee', 20, 4)->comment('手续费');
            $table->unsignedDecimal('deal_number', 20, 8)->nullable()->default(0)->comment('已成交数量');
            $table->unsignedDecimal('total', 20, 8)->nullable()->default(0)->comment('已成交金额');
            $table->unsignedTinyInteger('status')->nullable()->default(0)->comment('订单状态：0-未完全成交，1-完全成交，2-已撤销');
            $table->timestamp('created_at')->nullable()->useCurrent()->comment('挂单时间');
            $table->timestamp('updated_at')->nullable()->useCurrent()->comment('最后操作时间');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('trading_spot_orders');
    }
}
